<template>
	<view class="body">
		<view class="search-box">
			<input type="text" placeholder="请输入或扫描条码" class="search-input" v-model="code" @confirm="doByInput" confirm-type="search"/>
			<view class="search-btn" @tap="doByInput">
				<image src="../../static/icons/icon_search2.png" class="btn-icon"></image>
			</view>
			<!-- /btn-group -->
		</view>
		<view class="divider">
			
		</view>	
		<!-- <view class="menu-wrapper">
			<input type="text" placeholder="请输入或扫描条码" class="input" :value="code" @confirm="doByInput" confirm-type="search"/>			
		</view>
		<view class="divider">
			
		</view> -->
		<view class="menu-wrapper">
			产品条码 : {{part_code}}
		</view>
		<view class="menu-wrapper">
			产品名称 : {{part_name}}
		</view>
		<view class="menu-wrapper">
			产品型号 : {{part_specs}}
		</view>
		<view class="menu-wrapper">
			货位编码 : {{inventlocdef_code}}
		</view>
		<view class="menu-wrapper">
			MPS : {{plnmpsb_id}}
		</view>
		<view class="menu-wrapper">
			订单编号 : {{saleord_ord}}
		</view>
		<view class="menu-wrapper">
			出/入库 : {{part_code_ck_status}}/{{part_code_rk_status}}
		</view>
		<view class="menu-wrapper">
			备注 : {{part_comment}}
		</view>
		<view class="menu-wrapper">
			修改人 : {{modify_who}}
		</view>
		<view class="menu-wrapper">
			修改日期 : {{modify_date}}
		</view>
	</view>
</template>

<script>
	import SCan from 'common/scan.js'
	
	export default {
		data() {
			return {
				code:"",
				part_code:"",
				inventlocdef_code:"",
				plnmpsb_id:"",
				part_code_amnt:"",
				part_code_rk_status:"",
				part_code_ck_status:"",
				modify_who:"",
				modify_date:"",
				part_name:"",
				part_id:"",
				part_specs:"",
				saleord_ord:"",
				part_comment:""
			}
		}, 
		onShow: function(){  
			if(this.$config.SysConfig.wrhus_id==""|| this.$config.SysConfig.inventlocdef_code=="" || this.$config.SysConfig.wrhus_id==undefined|| this.$config.SysConfig.inventlocdef_code==undefined){
				uni.showModal({
					title:'提示',
					content:'当前仓库和货位未知,请先扫描货位码!',
					success: (res) => {
						if (res.confirm) {
							uni.navigateTo({
								url:'../wrhus/wrhus?index=offline'
							})
						}
						else{
							uni.navigateBack({
								delta:1
							})
						}
					}
				})
			} else {
				uni.setNavigationBarTitle({
					title:"下线扫描 "+this.$config.SysConfig.wrhus_id+"--"+this.$config.SysConfig.inventlocdef_code
				})
			}
			
		    SCan.initScan(this.queryAndScan)  
		    SCan.startScan();  
		},  
		onHide:function(){  
		    SCan.stopScan();  
		},  
		onUnload:function(){
		    SCan.stopScan();
		}, 
		onNavigationBarButtonTap:function(e){
			const index=e.index;
			if(index===0){
				uni.showActionSheet({
					itemList:['切换货位'],
					success:function(res){
						if(res.tapIndex===0){
							uni.redirectTo({
								url:'../wrhus/wrhus?index=offline'
							})
						}
					}
				})
			}
		},
		methods: {
			doByInput(e){
				var _this=this;
				_this.queryAndScan(_this.code);//e.detail.value)
			},
			queryAndScan(code){
				var _this=this;
				_this.$common.checkPopedom(()=>{
					_this.code=code;
					if(_this.code!=""){	
						//扫码记录日志
						var date=new Date();
						this.$config.SysConfig.TODAY_SCAN.push({
							page:'下线',
							code:code,
							date:date.getHours()+':'+date.getMinutes()+":" +date.getSeconds()
						})
						
						if(_this.$config.SysConfig.APP_ISONLINE){		
							//在线
							this.$common.isWifiExec(()=>{
								var param={
									barcode:_this.code.replace(/[\r\n]/g,""),
									locatorno:_this.$config.SysConfig.wrhus_id+"--"+_this.$config.SysConfig.inventlocdef_code,
									userid:_this.$config.SysConfig.loginedUser.loginname
								}
								_this.$http.offline(param).then((res)=>{
									if(res.code=='1'){
										_this.part_code=res.data.part_code
										_this.inventlocdef_code=res.data.inventlocdef_code
										_this.plnmpsb_id=res.data.plnmpsb_id
										_this.part_code_amnt=res.data.part_code_amnt
										_this.part_code_rk_status=res.data.part_code_rk_status
										_this.part_code_ck_status=res.data.part_code_ck_status
										_this.modify_who=res.data.modify_who
										_this.modify_date=res.data.modify_date
										_this.part_name=res.data.part_name
										_this.part_specs=res.data.part_specs
										_this.part_comment=res.data.part_comment
										_this.saleord_ord=res.data.saleord_ord
									}
									else{
										_this.$common.playErrBeep(1)
										SCan.stopScan();
										uni.showModal({
											title:'提醒',
											content:res.msg,
											showCancel:false,
											success: (resp) => {
												if(resp.confirm){
													SCan.startScan();
												}
											}
										})
									}								
									// console.log(res)
								})
							},()=>{
								uni.showToast({
									icon:'none',
									title:this.$config.msgs.needwifi,
									duration:1500
								})
								// uni.showToast(this.$config.msgs.needwifi)
							})
						}
						else
						{ //离线 无法查询
							uni.showToast({
								icon:'none',
								duration:1500,
								title:this.$config.msgs.needonline
							})
							// uni.showToast(this.$config.msgs.needonline)
							// _this.$common.playErrBeep(1)
						}					
					}
					else {
						console.log('err')						
						// _this.$common.playErrBeep(1)
					}
				})
			}
		}
	}
</script>

<style>
.body{
	border-top: solid 1px #DBDBDA;
	padding: 0upx;
}
.input{
	width: 100%;
	height: 85upx;
	padding-right: 80upx;
	background: url('../../static/icons/qrcode.png') no-repeat scroll right center transparent;	
}
.menu-wrapper{
	flex-direction: row;
	display: flex;
	margin-top: 25upx;
	padding: 5upx 35upx;
}
.menu-wrapper button{
	width: 160upx;
}
.search-box {
    display: flex;
	flex-direction: row;
	padding: 0upx 15upx;
}
.search-input {
   flex-grow: 11;
   height: 75upx;
   line-height: 80upx;
}
.search-btn {
    flex: 1;
	border: none;	
	padding: 10upx 10upx 5upx 10upx;
}
.btn-icon{
	width: 60upx;
	height: 60upx;
	line-height: 80upx;
}
.divider{
	border-top: solid 4upx #ADADAD;
	height: 1upx;
}
</style>
